<template>
  <el-dialog
    title="选择父级"
    :visible.sync="show"
    :close-on-click-modal="false"
    :show-close="false"
    width="400px"
    @open="openFn"
  >
    <Tree ref="tree" :data="treeNodeData" @on-select-change="nodeClick" />
    <span slot="footer" class="dialog-footer">
      <el-button @click="btn_clickCancel">取 消</el-button>
      <el-button type="primary" @click="bnt_clickConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>

export default {
  name: '',
  components: {},
  props: {
    show: { type: Boolean, default: false }
  },
  data() {
    return {
      loading: false,
      nodeData: {}, // 当前选中节点数据
      treeNodeData: [] // 树形节点数据
    }
  },
  mounted() {},
  methods: {
    // 对话框打开的回调
    openFn() {
      this.getTreeData()
    },
    // 监听当前节点数据选择
    nodeClick(v) {
      this.nodeData = v[0]
    },
    // 获取树型数据
    getTreeData() {
      this.treeNodeData = JSON.parse(sessionStorage.getItem('treeList'))
    },
    // 按钮事件-取消
    btn_clickCancel() {
      this.$emit('closed', false)
    },
    // 按钮确定事件
    bnt_clickConfirm() {
      this.$emit('closed', this.nodeData)
    }
  }
}
</script>
